#include "errcode.h"

#include <string.h>

struct err_code{
    char_t *code;
    char_t *desc;  
};


static const struct err_code g_start_ack_fail[]={
    /*0x00*/   {"0000", "成功"},
    /*0x01*/   {"301A", "数据合法性校验失败"},
    /*0x02*/   {"301A", "充电控制器与计费控制单元通讯超时"},
    /*0x03*/   {"301A", "充电控制器与计费单元[版本校验]未完成"},
    /*0x04*/   {"301A", "充电控制器与计费单元[下发充电参数]未完成"},   
    /*0x05*/   {"3029", "充电桩暂停服务"},
    /*0x06*/   {"100C", "充电桩处于工作状态"},
    /*0x07*/   {"100C", "充电桩处于暂停状态"},
    /*0x08*/   {"100D", "充电桩与车辆处于未连接状态"},
    /*0x09*/   {"3003", "急停按钮动作故障"},
    /*0x0a*/   {"3002", "门禁故障"},
    /*0x0b*/   {"400C", "避雷器故障"},
    /*0x0c*/   {"3019", "烟感故障"},
    /*0x0d*/   {"3016", "充电桩过温故障"},
    /*0x0e*/   {"3017", "充电接口过温故障"},
    /*0x0f*/   {"3018", "充电接口电子锁故障"},
    /*0x10*/   {"3014", "绝缘监测故障"},
    /*0x11*/   {"501A", "电池极性反接故障"},
    /*0x12*/   {"5000", "BMS 通信超时故障"},
    /*0x13*/   {"4005", "输入高压断路器故障"},
    /*0x14*/   {"4005", "输入高压接触器误动故障"},
    /*0x15*/   {"4005", "输入高压接触器粘连故障"},
    /*0x16*/   {"3010", "输出高压接触器误动故障"},
    /*0x17*/   {"300F", "输出高压接触器粘连故障"},
    /*0x18*/   {"3011", "输出高压熔断器故障"},
    /*0x19*/   {"3010", "并联接触器误动故障"},
    /*0x1a*/   {"300F", "并联接触器粘连故障"},
    /*0x1b*/   {"3015", "泄放回路故障"},
    /*0x1c*/   {"3013", "辅助电源故障"},
    /*0x1d*/   {"300A", "充电机模块故障"},
    /*0x1e*/   {"4000", "输入电源故障"},
    /*0x1f*/   {"4001", "输出电压过压故障"},
    /*0x20*/   {"4003", "输出电压欠压故障"},
    /*0x21*/   {"4002", "输出电流过流故障"},
    /*0x22*/   {"4004", "输出短路故障"},
    /*0x23*/   {"4008", "无空余充电机模块可用"},
    /*0x24*/   {"400D", "充电桩其他故障"},
};

#define g_start_ack_fail_len (sizeof(g_start_ack_fail)/sizeof(struct err_code))

char_t *errcode_get_start_ack_fail_code(int32_t code){
    if(code > g_start_ack_fail_len){
        code = g_start_ack_fail_len;
    }
    return g_start_ack_fail[code].code;
}


char_t *errcode_get_start_ack_fail_desc(int32_t code){
    if(code > g_start_ack_fail_len){
        code = g_start_ack_fail_len;
    }
    return g_start_ack_fail[code].desc;
}


static const struct err_code g_start_finish_fail[]={
    /*0x00*/   {"0000", "未知异常"},
    /*0x01*/   {"301B", "充电中控制导引故障"},
    /*0x02*/   {"301A", "充电控制器与计费控制单元通信超时"},
    /*0x03*/   {"3003", "急停按钮动作故障"},
    /*0x04*/   {"3002", "门禁故障"},   
    /*0x05*/   {"400C", "避雷器故障"},
    /*0x06*/   {"3019", "烟感故障"}, //液位报警
    /*0x07*/   {"4005", "交流输入断路器故障"},
    /*0x08*/   {"4005", "交流输入接触器误动故障"},
    /*0x09*/   {"4005", "交流输入接触器粘连故障"},
    /*0x0a*/   {"4000", "交流输入故障"},
    /*0x0b*/   {"3016", "充电桩过温故障"},
    /*0x0c*/   {"3017", "充电接口过温故障"},
    /*0x0d*/   {"3018", "充电接口电子锁故障"},
    /*0x0e*/   {"3014", "绝缘监测故障"},
    /*0x0f*/   {"501A", "电池极性反接故障"},
    /*0x10*/   {"3010", "直流输出接触器误动故障"},
    /*0x11*/   {"300F", "直流输出接触器粘连故障"},
    /*0x12*/   {"3011", "直流输出熔断器故障"},
    /*0x13*/   {"3012", "并联接触器误动故障"},
    /*0x14*/   {"3012", "并联接触器粘连故障"},
    /*0x15*/   {"3015", "泄放回路故障"},
    /*0x16*/   {"3013", "辅助电源故障"},
    /*0x17*/   {"300A", "充电模块故障"},
    /*0x18*/   {"4001", "直流输出电压过压故障"},
    /*0x19*/   {"4003", "直流输出电压欠压故障"},
    /*0x1a*/   {"4002", "直流输出电流过流故障"},
    /*0x1b*/   {"4004", "直流输出短路故障"},
    /*0x1c*/   {"501C", "电池最高允许充电电压小于充电机最小输出电压"},
    /*0x1d*/   {"4006", "绝缘监测前直流输出接触器外侧电压大于10v"},
    /*0x1e*/   {"500C", "启动充电前直流输出接触器外侧电压与通信报文电池电压相差大于正负5%"},
    /*0x1f*/   {"501B", "启动充电前直流输出接触器外侧电压小于充电机最小输出电压"},
    /*0x20*/   {"500F", "启动充电前直流输出接触器外侧电压大于充电机最大输出电压"},
    /*0x21*/   {"501C", "电池端电压大于电池最高允许充电电压"},
    /*0x22*/   {"500A", "BRM 报文接收超时"},
    /*0x23*/   {"500A", "BRM 报文数据异常"},
    /*0x24*/   {"5001", "BCP 报文接收超时"},
    /*0x25*/   {"5001", "BCP 报文数据异常"},
    /*0x26*/   {"5002", "BRO 报文(0X00)接收超时"},
    /*0x27*/   {"5002", "BRO 报文(0XAA)接收超时"},
    /*0x28*/   {"301D", "充电机其他故障"},
    
    /*0x29*/   {"5002", "充电机启动超时"},
    /*0x2A*/   {"5002", "充电机准备超时"},
    /*0x2B*/   {"500C", "需求电压超出范围"},
    /*0x2C*/   {"3008", "交直流模块通讯中断"},
    /*0x2D*/   {"5011", "BMS其他故障"}, //占位
    /*0x2E*/   {"5011", "BMS其他故障"}, //占位
    /*0x2F*/   {"5011", "BMS其他故障"}, //占位
    /*0x30*/   {"5011", "BMS其他故障"}, //占位
    /*0x31*/   {"5011", "BMS其他故障"}, //占位
    /*0x32*/   {"3004", "风机故障"},
    /*0x33*/   {"5011","BMS其他故障"}, //占位
    /*0x34*/   {"5011","BMS其他故障"}, //占位
	/*0x35*/   {"400D", "电流采样异常"},
	/*0x36*/   {"5011","BMS其他故障"}, //占位
	/*0x37*/   {"5011","BMS其他故障"}, //占位
	/*0x38*/   {"5000", "充电机通讯中断"},	
       
};

#define g_start_finish_fail_len (sizeof(g_start_finish_fail)/sizeof(struct err_code))

char_t *errcode_get_start_finish_fail_code(int32_t code){
    if (code > g_start_finish_fail_len){
        code = g_start_finish_fail_len;
    }
    return g_start_finish_fail[code].code;
}

//注意0x28需根据需求变动
char_t *errcode_get_start_finish_fail_desc(int32_t code){
    if (code > g_start_finish_fail_len){
        code = g_start_finish_fail_len;
    }
    return g_start_finish_fail[code].desc;
}

static const struct err_code g_stop_finish_fail[]={
    /*0x00*/   {"0000", "NULL"},
    /*0x01*/   {"1000", "计费控制单元正常停止"},
    /*0x02*/   {"301D", "计费控制单元自身故障停止"},
    /*0x03*/   {"301D", "计费控制单元判断充电控制器故障停止"},
    /*0x04*/   {"301A", "启动完成状态帧确认超时故障终止"},   
    /*0x05*/   {"301B", "充电中控制导引故障"},
    /*0x06*/   {"301A", "充电控制器与计费控制单元通信超时"},
    /*0x07*/   {"301D", "充电桩充电中暂停超时"},
    /*0x08*/   {"3003", "急停按钮动作故障"},
    /*0x09*/   {"3002", "门禁故障"},
    /*0x0a*/   {"400C", "避雷器故障"},
    /*0x0b*/   {"3019", "烟感故障"},
    /*0x0c*/   {"4005", "交流输入断路器故障"},
    /*0x0d*/   {"4005", "交流输入接触器误动故障"},
    /*0x0e*/   {"4005", "交流输入接触器粘连故障"},
    /*0x0f*/   {"4000", "交流输入故障"},
    /*0x10*/   {"3016", "充电桩过温故障"},
    /*0x11*/   {"3017", "充电接口过温故障"},
    /*0x12*/   {"3018", "充电接口电子锁故障"},
    /*0x13*/   {"3010", "直流输出接触器据动/误动故障"},
    /*0x14*/   {"300F", "直流输出接触器粘连故障"},
    /*0x15*/   {"3011", "直流输出熔断器故障"},
    /*0x16*/   {"3010", "并联接触器据动/误动故障"},
    /*0x17*/   {"300F", "并联接触器粘连故障"},
    /*0x18*/   {"3015", "泄放回路故障"},
    /*0x19*/   {"3013", "辅助电源故障"},
    /*0x1a*/   {"300A", "充电机模块故障"},
    /*0x1b*/   {"4001", "直流输出电压过压故障"},
    /*0x1c*/   {"4003", "直流输出电压欠压故障"},
    /*0x1d*/   {"4002", "直流输出电流过流故障"},
    /*0x1e*/   {"4004", "直流输出短路故障"},
    /*0x1f*/   {"5004", "电池充电需求报文（BCL）超时"},
    /*0x20*/   {"5003", "电池充电总状态报文（BCS）超时"},
    /*0x21*/   {"5007", "动力蓄电池状态信息（BSM）超时"},
    /*0x22*/   {"5012", "BSM 报文中单体动力蓄电池电压过压"},
    /*0x23*/   {"5013", "BSM 报文中单体动力蓄电池电压过低"},
    /*0x24*/   {"5014", "BSM 报文中 SOC 过高"},
    /*0x25*/   {"5015", "BSM 报文中 SOC 过低"},
    /*0x26*/   {"5016", "BSM 报文中充电过电流"},
    /*0x27*/   {"5017", "BSM 报文中动力蓄电池温度过高"},
    /*0x28*/   {"5018", "BSM 报文中动力蓄电池绝缘状态异常"}, 
    /*0x29*/   {"5019", "BSM 报文中连接器连接状态异常"},
    /*0x2a*/   {"100B", "BMS 正常终止充电"},
    /*0x2b*/   {"100A", "BMS 异常终止充电"},
    /*0x2c*/   {"5011", "充电桩判断 BMS 其他异常终止"},
    /*0x2d*/   {"301D", "充电桩其他故障"}, 
    //以下自己添加
    /*0x2e*/   {"5011", "接收SPN2560=0X00的充电机报文超时"},
    /*0x2f*/   {"5011", "接收SPN2560=0XAA的充电机报文超时"},
    /*0x30*/   {"5011", "接收充电机的时间同步和最大输出能力报文超时"},
    /*0x31*/   {"501D", "接收充电机完成充电准备报文超时"},
    /*0x32*/   {"501E", "接收充电机充电状态报文超时"},
    /*0x33*/   {"501F", "接收充电机中止充电报文超时"},
    /*0x34*/   {"5020", "接收充电机充电统计报文超时"},
    /*0x35*/   {"5011", "BMS其他错误"},
    /*0x36*/   {"500A", "接收  BMS和车辆的辨识报文超时"},
    /*0x37*/   {"5011", "接收电池充电参数报文超时"},
    /*0x38*/   {"5002", "接收BMS完成充电准备报文超时"},
    /*0x39*/   {"5003", "接收电池充电总状态报文超时"},
    /*0x3a*/   {"5004", "接收电池充电要求报文超时"},
    /*0x3b*/   {"5005", "接收BMS中止充电报文超时"},
    /*0x3c*/   {"5006", "接收BMS充电统计报文超时"},
    /*0x3d*/   {"5011", "充电机其他错误"},
};

#define g_stop_finish_fail_len (sizeof(g_stop_finish_fail)/sizeof(struct err_code))

char_t *errcode_get_stop_resion_code(int32_t code){
    if (code > g_stop_finish_fail_len){
        code = g_stop_finish_fail_len;
    }
    return g_stop_finish_fail[code].code;
}

char_t *errcode_get_stop_resion_desc(int32_t code){
    if (code > g_stop_finish_fail_len){
        code = g_stop_finish_fail_len;
    }
    return g_stop_finish_fail[code].desc;
}


